//
//  CLDocViewController.m
//  chanlin
//
//  Created by Ryan on 14-11-13.
//  Copyright (c) 2014年 chanlin. All rights reserved.
//

#import "CLDocViewController.h"
#import "CLDocModel.h"
#import "CLDocumentModel.h"
#import "BlockUI.h"
#import "SgrGCD.h"
#import "INHtmlElement.h"
#import "CLDocHeadImgCell.h"
#import "CLTitleCell.h"
#import "CLTextCell.h"
#import "CLDocImageCell.h"
#import "IDocTextCell.h"
#import "TimeCell.h"
#import "IfengDocRelationCell.h"
#import "IfengDocRelationTitleCell.h"
#import "CLComentDataModel.h"
#import "CTCommentViewController.h"
#import "PanPushAnimationFromRight.h"
#import "CLNavigationController.h"
#import "CalculatHeightForReplayCell.h"
#import "IfSectionCell.h"
#import "UIView+Utils.h"
#import "CommentCommonCell.h"
#import "INHtmlElementUtil.h"
#import "TitleCell.h"
#import "CLSlidersViewController.h"
#import "CLPushAnimatedRight.h"
#import "AQRImageZoomView.h"
#import "UIImageView+WebCache.h"
#import "CLSlidersViewController.h"
#import "CLPushAnimatedRight.h"
#import "CLDocViewController.h"
#import "CLTopicViewController.h"
#import "CLPushAnimated.h"
#import "ClEntityHead.h"
#import "CLVideoViewController.h"
#import "ReadDocHistory.h"
#import "CTDocAudioCell.h"
#import "IFAudioPlayerManager.h"
#import "CLDocBeFromCell.h"
#import "CLSubViewController.h"
#import "CLGlobleDataModel.h"

#import "CLList.h"
#import "IFCoreDataManager.h"

#import "CLDocQuickShareCell.h"
#import "IFIndexTitleCell.h"
#import "CLDocWeiDianCell.h"

#import "CLLiveViewController.h"

#import "CLDocFocusCell.h"
#import "CLWebVeiwController.h"
#import "IFIndexIconCell.h"
#import "IfBindMultipleScrollView.h"
#import "IFMoviePlayerController.h"
#import "SgrGCD.h"

#define sec_doc_sections_count 5  //加一是为了核心提示
#define sec_doc_titleImage 90
#define sec_doc_title 91
#define sec_doc_focus 92
#define sec_doc_weidian (93)
#define sec_doc_doc (94)

#define sec_doc_relation (2)
#define sec_doc_comment (3)
#define sec_doc_beFrom 1
#define sec_doc_quickshare (0)
#define sec_doc_blank 4

@interface CLDocViewController()

- (void)playVideo:(int) index frame:(CGRect )frame;
- (void)showBigPic:(NSString *)url frame:(CGRect) frame;
- (void)goToComment;
- (void)gotoSlides;

@end


@implementation IFDocAction2

- (void)playVideo:(int )index top:(float )top left:(float )left width:(float )width height:(float )height{
    
    __weak typeof(self) me=self;
    [[SgrGCD sharedInstance] enqueueForeground:^{
        [me.doc playVideo:index frame:CGRectMake(left, top, width, height)];
    }];
    
}

- (void)showPic:(NSString *)url top:(float )top left:(float )left width:(float )width height:(float )height{
    __weak typeof(self) me=self;
    [[SgrGCD sharedInstance] enqueueForeground:^{
        [me.doc showBigPic:url frame:CGRectMake(left, top, width, height)];
    }];
    
}

- (void)dispatchLink:(NSString *)type url:(NSString *)url{
    __weak typeof(self) me=self;
//    [[SgrGCD sharedInstance] enqueueSafeMain:^{
//        [me.doc dispatchLink:type url:url];
//    }];
}

- (void)goSlides:(NSString *)url{
    __weak typeof(self) me=self;
    [[SgrGCD sharedInstance] enqueueForeground:^{
        [me.doc gotoSlides];
    }];
    
}

- (void)goOrigin:(NSString *)url{
    __weak typeof(self) me=self;
//    [[SgrGCD sharedInstance] enqueueSafeMain:^{
//        [me.doc goOrigin:url];
//    }];
}

- (void)gotoComment{
    __weak typeof(self) me=self;
    [[SgrGCD sharedInstance] enqueueForeground:^{
        [me.doc goToComment];
    }];
}

@end


@interface CLDocViewController ()

@property (nonatomic,strong)CLDocumentModel *document;
@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,strong)UIActivityIndicatorView *active;
@property (nonatomic,strong)NSString *commnetDocID;
@property (nonatomic,strong) CTCommentViewController *commentVC;
@property (nonatomic,strong) PanPushAnimationFromRight *panpushAnimation;

@property (nonatomic, strong)TimeCell *cell;

@property (nonatomic,strong) UIView *bigImgView;
@property (nonatomic,weak) CTDocAudioCell *audioCell;

@property (nonatomic,strong)UIView *audioView;

@property (nonatomic,strong)UISlider *slider;

@property (nonatomic,strong)UILabel *sliderLabel;

@property (nonatomic,strong)UIButton *play;
@property (nonatomic,strong)UIButton *more;

@property (nonatomic, strong)CLDocHeadImgCell *headImgView;
@property (nonatomic, strong)UIView *headerView;

@property (nonatomic,assign)BOOL isSlider;

@property (nonatomic,strong)IfBindMultipleScrollView *bindView;

@property (nonatomic,strong)UIWebView *webView;

@property (nonatomic,unsafe_unretained)CGFloat fitSizeY;

@property (nonatomic,unsafe_unretained)CGRect headframe;

@property (nonatomic,strong) IFMoviePlayerController *pc;

@property (nonatomic,strong)IFDocAction2 *action;

@property (nonatomic,strong)JSContext *jsContext;

@property (nonatomic,unsafe_unretained )BOOL isShowPic;



@end

@implementation CLDocViewController

- (void)dealloc{
//    if(self.isRunAudio){
//       
//            [[IFAudioPlayerManager shareInstance] stop];
//        
//    }
    
    if(self.pc){
        [[CLGloble sharedInstance] clearMovie];
    }
    
    if([IFAudioPlayerManager shareInstance].isPlaying &&
       [[IFAudioPlayerManager shareInstance].tag isEqualToString:self.document.entity.itmeId]&&
       [IFAudioPlayerManager shareInstance].isPause){
        [[IFAudioPlayerManager shareInstance] stop];
    }
    
   // [[IFAudioPlayerManager shareInstance] notHiddenStateWindwo];
    
    [((CLNavigationController *)[self k_rootController]).panGesture removeTarget:self
                                                                          action:@selector(doPanRecognizer:)];
}




- (void)viewDidLoad {
    [super viewDidLoad];
    //self.itemId=@"5259";
  
    
    self.edgesForExtendedLayout = UIRectEdgeNone;
    self.extendedLayoutIncludesOpaqueBars = NO;
    self.modalPresentationCapturesStatusBarAppearance = NO;

    self.view.backgroundColor=RGB(0xf8, 0xf8, 0xf8);
    
    
    IfBindMultipleScrollView *v = [[IfBindMultipleScrollView alloc] initWithFrame:self.view.bounds];
 
        v.top=20.f;
        v.height-=20.f;
    
    v.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
    v.backgroundColor=self.view.backgroundColor;
    //self.webView.backgroundColor=[UIColor orangeColor];
    
    [self.view addSubview:v];
    self.bindView=v;
    
    
    self.webView=[[UIWebView alloc] initWithFrame:self.view.bounds];
    self.webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    self.webView.backgroundColor=[UIColor clearColor];
    self.webView.scrollView.bounces=YES;
    self.webView.frame=self.view.bounds;
    self.tableView.scrollsToTop=YES;
    self.tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
    self.webView.delegate=self;
    
    self.webView.frame=self.view.bounds;
    //  [self.view addSubview:self.webView];
    
    v.topWebView = self.webView;
    
    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    self.tableView.decelerationRate = UIScrollViewDecelerationRateFast;
    self.tableView.backgroundColor=[UIColor clearColor];
    //    UIView *bgview=[UIView new];
    //    self.tableView.backgroundView=bgview;
    //bgview.backgroundColor=self.view.backgroundColor;
    self.tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
    self.tableView.separatorColor=[UIColor clearColor];
    self.tableView.bounces=NO;
    self.tableView.scrollsToTop=NO;
    self.tableView.delegate=self;
    self.tableView.dataSource=self;
    
    self.tableView.contentInset=UIEdgeInsetsMake(0, 0, 44.f, 0);
    [v addBindScrollView:self.tableView];
    
    self.document=[[CLDocumentModel alloc] init];
    [self requestData];
    
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(picShowComplete)
                                                 name:@"PicShowComplete"
                                               object:nil];
    
    UIPinchGestureRecognizer *pinchGr = [[UIPinchGestureRecognizer alloc] init];
    [pinchGr addTarget:self action:@selector(_pinchGr:)];
    [self.webView addGestureRecognizer:pinchGr];
    [self createNavigation];
    
    if(!self.commentVC){
        self.commentVC = [[CTCommentViewController alloc] init];
        self.commentVC.isNeedRequest=NO;
        self.commentVC.fromtype=@"doc";
        self.panpushAnimation=[[PanPushAnimationFromRight alloc] init];
        // self.panpushAnimation.pathName=self.document.documentId;
        [self.panpushAnimation addNextController:self.commentVC];
        // self.panpushAnimation.animationType=Dispatch_AnimationType_push;
        
        [((CLNavigationController *)[self k_rootController]).panGesture addTarget:self action:@selector(doPanRecognizer:)];
    }


    
    /*
    
    self.tableView=[[UITableView alloc] init];
    self.tableView.frame=self.view.bounds;
    self.tableView.contentInset=UIEdgeInsetsMake(20.0f, 0, 44.f, 0);
    self.tableView.backgroundColor=self.view.backgroundColor;
    self.tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
    UIView *bg=[UIView new];
    bg.backgroundColor=self.view.backgroundColor;
    self.tableView.backgroundView=bg;
    self.tableView.delegate=self;
    self.tableView.dataSource=self;
    [self.view addSubview:self.tableView];
    UIView *head=[UIView new];
    head.backgroundColor=RGB(0xf8, 0xf8, 0xf8);
    head.frame=CGRectMake(0, 0, GlobleWidth, 20.f);
    [self.view addSubview:head];
    
    [self createNavigation];
    if(!self.commentVC){
        self.commentVC = [[CTCommentViewController alloc] init];
        self.commentVC.isNeedRequest=NO;
        self.commentVC.fromtype=@"doc";
        self.panpushAnimation=[[PanPushAnimationFromRight alloc] init];
       // self.panpushAnimation.pathName=self.document.documentId;
        [self.panpushAnimation addNextController:self.commentVC];
       // self.panpushAnimation.animationType=Dispatch_AnimationType_push;
        
        [((CLNavigationController *)[self k_rootController]).panGesture addTarget:self action:@selector(doPanRecognizer:)];
    }
    
    self.document=[[CLDocumentModel alloc] init];
    [self requestData];
    
    UIPinchGestureRecognizer *pinchGr = [[UIPinchGestureRecognizer alloc] init];
    [pinchGr addTarget:self action:@selector(_pinchGr:)];
    [self.tableView addGestureRecognizer:pinchGr];
     
     */
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showYinpinTool:) name:@"showYinpinTool" object:nil];
}


- (void)doPanRecognizer:(UIPanGestureRecognizer *)recognizer{
    if(self!=[self k_currentController])return;
    
    [self.panpushAnimation doAnimation:recognizer];
    
}

- (void)requestComment{
    __weak typeof(self) me=self;
     [[CLComentDataModel sharedInstance] loadTopicWithUrl:nil
                                                    title:self.document.entity.title
                                                      doc:self.itemId
                                                    block:^(BOOL success, NSDictionary *dic) {
                                                        if(success){
                                                            me.document.commentsArray=[[dic sgrGetDictionaryForKey:@"comments"] sgrGetArrayForKey:@"newest"];
                                                            me.commentVC.docTitle=me.document.entity.title;
                                                            me.commentVC.shareUrl=me.document.entity.shareUrl;
                                                            me.commnetDocID=[dic sgrFGetStringForKey:@"topic_id"];
                                                            me.commentVC.commentTopicId=me.commnetDocID;
                                                            [me.tool update:[dic sgrGetIntForKey:@"count"]];
                                                            [me.cell setComentNum:[dic sgrGetIntForKey:@"count"]];
                                                            [me.webView stringByEvaluatingJavaScriptFromString:
                                                             [NSString stringWithFormat:@"showUpcomment(%d)",[dic sgrGetIntForKey:@"count"]]];
                                                            [me.commentVC showCommentDic:dic];
                                                           [me addcommnet];
                                                        }else{
                                                            
                                                        }
                                                       // NSLog(@"%@",dic);
                                                        
                                                    }];
}

- (void)addcommnet{
    NSMutableArray *array=[NSMutableArray array];
    int n=[self commentCells];
    for(int i=0;i<n;i++){
        NSIndexPath *path=[NSIndexPath indexPathForRow:i inSection:sec_doc_comment];
        [array addObject:path];
    }
    [self.tableView insertRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationNone];
   
}

- (int)commentCells{
    int count=0;
    if(!self.document.commentsArray || [self.document.commentsArray count] == 0){
        count = 0;
    }
    else if(self.document.commentsArray && [self.document.commentsArray count] > 0)
    {
        if([self.document.commentsArray count] >=2)
            count=4;
        else
            count=[self.document.commentsArray count]+2;
    }
    return count;
}

- (float)caculateCommentsCell:(UITableView *)tableView :(int)row{
    
    int bottomRowIndex = 0;
    if([self.document.commentsArray count] >=2)
        bottomRowIndex = 3;
    else
        bottomRowIndex = [self.document.commentsArray count]+1;
    
    if(0==row){
        return 50.0f;
    }else if(bottomRowIndex==row){
        return 57.0f;
    }else{
        //        NSString *info=[[[self.document hottest]
        //                         sgrGetDictionaryForIndex:row-1]
        //                        sgrGetStringForKey:@"comment_contents"];
        NSDictionary *dic = [self.document.commentsArray sgrGetDictionaryForIndex:row-1];
        float f=[CalculatHeightForReplayCell calculationCommonCommentHeightWithData:dic];
        return f;
    }
}

- (void)createNavigation{
    self.tool=[self showToolbarWithType:IFActive_ButtomToolBarButtonTypeShare|IFActive_ButtomToolBarButtonTypeCollect|IFActive_ButtomToolBarButtonTypeFont|IFActive_ButtomToolBarButtonTypeShowComment|IFActive_ButtomToolBarButtonTypeWriteComment];
    __weak typeof(self) me=self;
    [self.tool handleTap:IFActive_ButtomToolBarButtonTypeWriteComment block:^(id sender) {
        if(_isStrNULL(me.commnetDocID)){
            [[CLGloble sharedInstance] showTieAlertMessage:@"暂时不能评论" subMessage:@"请稍后尝试"];
            return ;
        }
        [me openComment:me.commnetDocID replayId:nil block:^(NSString *cont, int select) {
            NSString *str=[NSString stringWithFormat:@"我的评论:%@ |%@ %@",_safeStr(cont),_safeStr(me.document.entity.title),
                           _safeStr(me.document.entity.shareUrl)];
            [[CLGlobleDataModel sharedInstance] shareMessage:select content:str];
        }];
    }];
    [self.tool handleTap:IFActive_ButtomToolBarButtonTypeShowComment block:^(id sender) {
        [me.panpushAnimation pushDirectly];
    }];
    
    [self.tool handleTap:IFActive_ButtomToolBarButtonTypeShare block:^(id sender) {

        
        NSMutableDictionary *dic=[NSMutableDictionary dictionary];
//        [dic sgrSetObject:[UIImage imageNamed:@"icon114.png"] forKey:@"icon"];
        
        [dic sgrSetObject:[me getImageFromURL:me.document.entity.sharepicUrl] forKey:@"icon"];

        [dic sgrSetObject:me.document.entity.title forKey:@"title"];
        
        
        [dic sgrSetObject:me.document.entity.shareUrl  forKey:@"url"];
        [me openShare:dic];
    }];
    
    __weak IFToolBarViewController *t=self.tool;
    [self.tool addListnerFont:^(int index){
        [t activeFontSize:index];
        [INHtmlElementUtil sharedInstance].level=index+1;
        [me changeFontSize];
        [[IFDocTemplate sharedInstance] changeFont];
        
        [me.webView stringByEvaluatingJavaScriptFromString:
         [NSString stringWithFormat:@"changeFont(%d)",[INHtmlElementUtil sharedInstance].level]];
        
       
        [[SgrGCD sharedInstance] enqueueForeground:^{
            CGSize size= [me.webView sizeThatFits:CGSizeZero];
            me.webView.scrollView.contentSize=CGSizeMake(GlobleWidth, size.height);
            me.fitSizeY=size.height;
            
            NSString *str=[me.webView stringByEvaluatingJavaScriptFromString:@"lastObjFrame();"];
            NSArray *arr=[str componentsSeparatedByString:@","];
            if([arr count]==4){
                
                float y=[arr[1] floatValue];
                if(y>0 && y<me.webView.height){
                    me.webView.height=y+5.f;
                    // 把contentSize改小会导致下面的tableView上移.
                    // 但bindView实现是通过contentSize来做padding的, 实际的contentSize会更大.
                    // 所以webView仍然会把期望的高度内容画出来, 导致对移上去的tableView造成覆盖.
                    // self.webView.scrollView.contentSize=CGSizeMake(GlobleWidth, self.webView.height);
                    me.fitSizeY=y+5.f;
                }
                
            }
            
            
        }];
        
        
    }];
    self.tool.collectId=self.itemId;
    
    if(self.isAudio){
        self.tool.view.hidden=YES;
    }
}

-(UIImage *)getImageFromURL:(NSString *)fileURL {
    UIImage * result;
    NSData * data = [NSData dataWithContentsOfURL:[NSURL URLWithString:fileURL]];
    result = [UIImage imageWithData:data];
    if (result) {
        return result;
    }else
        return [UIImage imageNamed:@"icon114.png"];
    
}

- (BOOL)showPopAction{
    return YES;
}

- (void)changeFontSize{
    [[INHtmlElementUtil sharedInstance] buidFont];
    [self.document linkElement:self.document.entity];
    [self.tableView reloadData];
    [[CLGloble sharedInstance] showTieSuccessMessage:@"提示" subMessage:[INHtmlElementUtil sharedInstance].fontDesc];
    
}

- (void)_pinchGr:(UIPinchGestureRecognizer *)gesture{
    if (gesture.state == UIGestureRecognizerStateBegan) {
        if (gesture.scale > 1.0) {
            if([INHtmlElementUtil sharedInstance].level<4){
                [INHtmlElementUtil sharedInstance].level++;
            }
            
        }else if(gesture.scale < 1.0){
            if([INHtmlElementUtil sharedInstance].level>1){
                [INHtmlElementUtil sharedInstance].level--;
            }
        }
        [self changeFontSize];
        [[IFDocTemplate sharedInstance] changeFont];
        
        [self.webView stringByEvaluatingJavaScriptFromString:
         [NSString stringWithFormat:@"changeFont(%d)",[INHtmlElementUtil sharedInstance].level]];
    
            __weak typeof(self)me=self;
            [[SgrGCD sharedInstance] enqueueForeground:^{
                CGSize size= [me.webView sizeThatFits:CGSizeZero];
                me.webView.scrollView.contentSize=CGSizeMake(GlobleWidth, size.height);
                me.fitSizeY=size.height;
                
                NSString *str=[me.webView stringByEvaluatingJavaScriptFromString:@"lastObjFrame();"];
                NSArray *arr=[str componentsSeparatedByString:@","];
                if([arr count]==4){
                    
                    float y=[arr[1] floatValue];
                    if(y>0 && y<me.webView.height){
                        me.webView.height=y+5.f;
                        // 把contentSize改小会导致下面的tableView上移.
                        // 但bindView实现是通过contentSize来做padding的, 实际的contentSize会更大.
                        // 所以webView仍然会把期望的高度内容画出来, 导致对移上去的tableView造成覆盖.
                        // self.webView.scrollView.contentSize=CGSizeMake(GlobleWidth, self.webView.height);
                        me.fitSizeY=y+5.f;
                    }
                    
                }
                
                
            }];

        
    }
}


- (void)requestData{
    self.active=[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    self.active.frame=CGRectMake(0, 0, 45.f, 45.f);
    [self.active setCenter:CGPointMake(self.view.frame.size.width/2.f, self.view.frame.size.height/2.f)];
    [self.view addSubview:self.active];
    [self.active startAnimating];
    __weak typeof(self) me=self;
     NSString *path=[[NSBundle mainBundle] pathForResource:@"docTemplate" ofType:@"html"];
   // self.itemId=@"7871";
    [[CLDocModel sharedInstance] getDoc:self.itemId
                                uiBlock:^(BOOL success, CLDocEntity *responseObj, NSString *message) {
                                    
                                    [me.active stopAnimating];
                                    
                                    
                                    if(success){
                                        [me.document linkElement:responseObj];
                                        [me.webView loadHTMLString:responseObj.html baseURL:[NSURL URLWithString:path]];
                                        if(_isStrNotNull(responseObj.audio)){
                                            [me createAudioView];
                                            [me checkStatus];
                                            me.tableView.contentInset=UIEdgeInsetsMake(0, 0, 80.f, 0);
                                        }
                                    }
                                    /*
                                    if(success){
                                        [[SgrGCD sharedInstance] enqueueGloble:^{
                                            [me.document linkElement:responseObj];
                                            sgrSafeMainThread(^{
                                                [me.active stopAnimating];
                                                [me.tableView reloadData];
                                                if(_isStrNotNull(responseObj.audio)){
                                                    [me createAudioView];
                                                    [me checkStatus];
                                                    me.tableView.contentInset=UIEdgeInsetsMake(0, 0, 80.f, 0);
                                                }
                                                
                                            })
                                            [me requestComment];
                                            [MobClick event:@"page"
                                                 attributes:@{@"pageId":[@"doc_" stringByAppendingString:_safeStr(me.document.entity.itmeId)],
                                                              @"title":_safeStr(me.document.entity.title)}];
                                        }];
                                    }else{
                                       [me.active stopAnimating];
                                        
                                    }
                                    */
                                    
                                }];

}



- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return sec_doc_sections_count;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    if (sec_doc_titleImage==section) {
        if(self.document.isReady && _isStrNotNull(self.document.entity.bigpic) &&
           
          _isStrNULL(self.document.entity.vurl) ){
            _headerView =[[UIView alloc] init];
            _headerView.frame = CGRectMake(0,0, GlobleWidth,(GlobleWidth*9.f)/16.f);
            _headImgView.backgroundColor = [UIColor redColor];
            
            static NSString *headImageId = @"CLDocHeadImgCell";
            if(_headImgView == nil){
                _headImgView = [[CLDocHeadImgCell alloc] initWithStyle:UITableViewCellStyleDefault
                                                       reuseIdentifier:headImageId];
            }
            _headImgView.backgroundColor = [UIColor redColor];
            [_headImgView loadImgUrl:self.document.entity.bigpic];
            [_headImgView setIsVideo:_isStrNotNull(self.document.entity.vurl) url:self.document.entity.vurl];
         
            
            
            [_headerView addSubview:_headImgView];
            
            
           // [_headerView addSubview:_headImgView.play];
            return _headerView;
        }else{
            return nil;
        }
    }else
        return nil;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    int count=0;
    switch (section) {
        case sec_doc_titleImage:
            if(self.document.isReady){
                count = 0;
                count=_isStrNotNull(self.document.entity.bigpic) && _isStrNotNull(self.document.entity.vurl)?1:0;
            }
            break;
        case sec_doc_title:
            count=self.document.isReady?2:0;
            break;
        case sec_doc_focus:
            count=_isStrNotNull(self.document.entity.smallText)?1:0;
            break;
        case sec_doc_doc:
            count=self.document.isReady?(int)self.document.entity.elements.count:0;
            break;
        case sec_doc_relation:
            count=self.document.isReady &&self.document.entity.relation.count>0?(int)self.document.entity.relation.count+1:0;
            break;
        case sec_doc_comment:
            count=[self commentCells];
            break;
        case sec_doc_beFrom:
            count=self.document.entity.dic?1:0;
            break;
        case sec_doc_quickshare:
            count=self.document.isReady?1:0;
            break;
        case sec_doc_weidian:
            count = _isStrNULL(self.document.entity.weiDianUrl)?0:1;
            break;
        case sec_doc_blank:
            count=1;
            break;
        default:
            break;
    }
    return count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    float height=0.f;
    switch (section) {
        case sec_doc_titleImage:
            if(self.document.isReady && _isStrNotNull(self.document.entity.bigpic)&&
               
               _isStrNULL(self.document.entity.vurl) ){
                height = (GlobleWidth*9.f)/16.f;
            }else
                height = 0;
            break;
        default:
            break;
            
    }
    return height;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    float height=0.f;
    int num = 0;
    CGSize size;
    INHtmlElement *element=nil;
    switch (indexPath.section) {
        case sec_doc_titleImage:
            if(_isStrNotNull(self.document.entity.vurl))
            height = 180.f;
            break;
        case sec_doc_title:
            if(indexPath.row==0){
                height=[TitleCellLabel cacult:self.document.entity.title]+25;
                if(height<80)
                height=80.f;}
            else if(indexPath.row==1)height=34.f;
            break;
        case sec_doc_focus:
            height = [IFLabel2 suggestHeightOfString:self.document.entity.smallText withWidth:275.f font:[UIFont systemFontOfSize:16] lineSpace:0]+38;
            if(_isStrNotNull(self.document.entity.bspic)  ){
                height+=24;
            }
            break;
        case sec_doc_doc:
            element=[self.document.entity.elements sgrGetType:[INHtmlElement class] forIndex:(int)indexPath.row];
            height=element.cellHeight;
            if(indexPath.row==(self.document.entity.elements.count-1)){
                height+=28.f;
            }
            break;
        case sec_doc_relation:
            if(self.document.entity.relation && [self.document.entity.relation count]>0){
                height=[self caculateRelationCell:tableView :indexPath.row];
//                if(indexPath.row==[self.document.entity.relation count]-1){
//                    height+=25.0f;
//                }
            }
        
            break;
            
    
        case sec_doc_comment:
            height=[self caculateCommentsCell:tableView :indexPath.row];
            break;
        case sec_doc_beFrom:
            height=self.document.entity.dic?62.f:0;
            break;
        case sec_doc_quickshare:
            height=120;
            break;
        case sec_doc_blank:
            height=44.f;
            break;
            
        case sec_doc_weidian:
            if (_isStrNotNull(self.document.entity.weiDianIntro)) {
                num = [self getSubStringShowNumsInStringBy:_document.entity.weiDianIntro andSubstring:@"\n"];
                UILabel *label = [[UILabel alloc]init];
                label.numberOfLines = 0;
                label.text = _document.entity.weiDianIntro;
                UIFont *fnt = [UIFont systemFontOfSize:13.f];
                label.font = fnt;
                size = [label.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:fnt,NSFontAttributeName, nil]];
            }
            if (_isStrNotNull(self.document.entity.weiDianUrl) && _isStrNotNull(self.document.entity.weiDianPicUrl)) {
                height = 20+(_isStrNotNull(self.document.entity.weiDianPicUrl)?self.document.entity.wdpicHeight:0)+(_isStrNotNull(self.document.entity.weiDianIntroTitle)?36:0)+(_isStrNotNull(self.document.entity.weiDianIntro)?(size.height+28):0)+32+30;
//                height = 20+(_isStrNotNull(self.document.entity.weiDianPicUrl)?self.document.entity.wdpicHeight:0)
//                +(_isStrNotNull(self.document.entity.weiDianIntroTitle)?36:0)+(num?(size.height+20):0);
//                NSLog(@"====%f",(num?(size.height+20):0));
            }else
                height = 0;
            
            break;
            
        default:
            break;
    }

    if(isnan(height)){
        height=0.f;
    }
    return height;
}

-(int)getSubStringShowNumsInStringBy:(NSString*)string andSubstring:(NSString*)Substring
{
    int count =0;
    NSRange range = [string rangeOfString:Substring];
    if(range.length>0)
    {
        count++;
        while (range.length>0) {
            int startIndex =range.location+range.length;
            int endIndex = string.length -startIndex;
            string= [string substringWithRange:NSMakeRange(startIndex, endIndex)];
            range = [string rangeOfString:Substring];
            if(range.length>0)
            {
                count++;
            }
        }
    }
    return count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell=nil;
    INHtmlElement *element=nil;
    switch (indexPath.section) {
        case sec_doc_titleImage:
           cell=[self createHeadImageCell:tableView];
            break;
        case sec_doc_title:
            if(indexPath.row==0)
            cell=[self createTitleCell:tableView];
            else if(indexPath.row==1){
                cell=[self createTimeCell:tableView];
            }
            break;
        case sec_doc_focus:
            cell = [self createFocusCell:tableView];
            break;
        case sec_doc_doc:
            element=[self.document.entity.elements sgrGetType:[INHtmlElement class] forIndex:(int)indexPath.row];
       
            
            cell=[self createHTMLElementCell:tableView
                                     element:element
                             isLastParagraph:indexPath.row==(self.document.entity.elements.count-1)];
           
            break;
        case sec_doc_relation:
            cell=[self createRelationCell:tableView :indexPath.row];
            break;
        case sec_doc_comment:
            cell=[self createCommentCell:tableView :indexPath.row];
            break;
        case  sec_doc_beFrom:
            cell=[self createBeFromCell:tableView];
            break;
            
        case sec_doc_quickshare:
            cell = [self createQuickShareCell:tableView];
            break;
        case sec_doc_weidian:
            cell = [self createWeiDianCell:tableView];
            break;
            
        default:
            break;
    }
    if(!cell){
        cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
    }

    return cell;
}

- (UITableViewCell *)createBeFromCell:(UITableView *)tableView{
    static NSString *identifier = @"CLDocBeFromCell";
    CLDocBeFromCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier];
    if(!cell){
        cell=[[CLDocBeFromCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        cell.backgroundColor=tableView.backgroundColor;
        
        
    }
    [cell loadData:self.document.entity.dic];
    return cell;
}


- (UITableViewCell *)createAudioCell:(UITableView *)tableView :(INHtmlElement *)element{
    
    
    static NSString *identifier = @"CTDocAudioCellId";
    
    CTDocAudioCell *cell=[tableView   dequeueReusableCellWithIdentifier:identifier];
    if(!cell){
        cell = [[CTDocAudioCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier ];
        self.audioCell=cell;
        cell.ctrl=self;
        
        
    }
    cell.url=element.strValue;
    if([IFAudioPlayerManager shareInstance].isPlaying &&
       [[IFAudioPlayerManager shareInstance].audioUrl isEqualToString:element.strValue]){
        [cell checkStatus];
        [IFAudioPlayerManager shareInstance].tag=[NSString stringWithFormat:@"%l",[self hash]];
        self.isRunAudio=YES;
    }
    
    return cell;
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
 
  //  if (_isStrNULL(self.document.entity.vurl)) {
//        CGFloat yOffset  = scrollView.contentOffset.y;
//        yOffset+=self.webView.height;
//        CGRect frame = _headerView.frame;
//        frame.size.height +=  (-yOffset);
//        frame.size.width = (frame.size.height*16)/9;
//        frame.origin.y = yOffset;
//        frame.origin.x = (GlobleWidth-frame.size.width)/2;
//        
//        _headerView.frame = frame;
   // }
    
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    if (_headerView &&_isStrNULL(self.document.entity.vurl)) {
        CGFloat yOffset  = scrollView.contentOffset.y;
            yOffset+=_fitSizeY;
         
        if (yOffset <=0) {
            
         
            
            CGRect f = _headframe;
            f.origin.y = yOffset;
            f.size.height +=  (-yOffset);
            f.size.width = (f.size.height*16)/9;
            f.origin.x = (GlobleWidth-f.size.width)/2;
            _headerView.frame = f;
            _headerView.frame = f;
             _headImgView.headImage.frame=_headerView.bounds;
        }
    }
    
    
    if(!self.audioCell) return;
    
    
    if( self.isRunAudio){
        float off=20.f;
        if ((CGRectGetMinY(self.audioCell.frame)-off) < self.tableView.contentOffset.y
            && self.audioCell.isFloating == NO
            && [IFAudioPlayerManager shareInstance].isRunning == YES) {
            // 浮起
            self.audioCell.isFloating = YES;
            CGRect frame=self.audioCell.bgView.frame;
           
                frame.origin.y=20.f;
            
            self.audioCell.bgView.frame=frame;
            
            [self.view addSubview:self.audioCell.bgView];
            
        }else if((CGRectGetMinY(self.audioCell.frame)-off)  > self.tableView.contentOffset.y
                 && [self.audioCell isFloating] == YES){
            self.audioCell.isFloating = NO;
            
            CGRect frame=self.audioCell.bgView.frame;
            
            frame.origin.y=0.f;
            
            self.audioCell.bgView.frame=frame;
            [self.audioCell addSubview:self.audioCell.bgView];
            
        }
    }
}

-(UITableViewCell *)createRelationCell:(UITableView *)tableView :(int)row{
    if(0==row){
        static NSString *cellId=@"relationTitleCellId";
        IfengDocRelationTitleCell *cell=[tableView dequeueReusableCellWithIdentifier:cellId];
        if(!cell){
            cell=[[IfengDocRelationTitleCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
            cell.backgroundColor=tableView.backgroundColor;
            
        }
        
        return cell;
    }else{
        NSDictionary *dic=[self.document.entity.relation sgrGetDictionaryForIndex:row-1];
        
        NSString *str=[dic sgrGetStringForKey:@"titlepic"];
        
        if(_isStrNULL(str)){
            static NSString *cellID=@"IFIndexTitleCell";
            IFIndexTitleCell *cell=[tableView dequeueReusableCellWithIdentifier:cellID];
            if(!cell){
                cell=[[IFIndexTitleCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
            }
            [cell loadDic:dic];
            return cell;
        }else{
            static NSString *cellID=@"IFIndexIconCell";
            IFIndexIconCell *cell=[tableView dequeueReusableCellWithIdentifier:cellID];
            if(!cell){
                cell=[[IFIndexIconCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
            }
            
            [cell loadDic:dic];
            int linkType=[[dic sgrFGetStringForKey:@"type"] intValue];
            
            [cell setPlayVideo:linkType==CLList_video];
            cell.backgroundColor=cell.contentView.backgroundColor=self.view.backgroundColor;
            return cell;
        }

        
        
//        static NSString *cellId=@"relationCellId";
//        IfengDocRelationCell *cell=[tableView dequeueReusableCellWithIdentifier:cellId];
//        if(!cell){
//            cell=[[IfengDocRelationCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
//            cell.backgroundColor=tableView.backgroundColor;
//        }
//        NSDictionary *dic=[self.document.entity.relation sgrGetDictionaryForIndex:row-1];
//        [cell setICONWithType:[dic sgrGetStringForKey:@"type"]];
//        [cell docDic:dic];
//
//       // [cell setComment:[[dic sgrGetStringForKey:@"comments"] intValue]];
//
//        
//        // 最后一个cell并且没有文字链广告，则隐藏分割线
//        // BOOL isLastCell = (row == [self.document relations].count) && (!self.hasADBanner);
//        [cell setTitle:[dic sgrGetStringForKey:@"title"] isLastCell:NO];
//        [cell setIsRead:[[ReadDocHistory shareInstance] check:[dic sgrGetStringForKey:@"id"]]];
       // return cell;
    }
}

- (UITableViewCell *)createQuickShareCell:(UITableView *)tableView {
    static NSString *quickShare = @"IDocQuickShareCell";
    CLDocQuickShareCell *cell = (CLDocQuickShareCell *)[tableView dequeueReusableCellWithIdentifier:quickShare];
    if (!cell) {
        cell = [[CLDocQuickShareCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:quickShare];
        cell.document = self.document;
    }
    return cell;
}

- (UITableViewCell *)createWeiDianCell:(UITableView *)tableView {
    static NSString *weiDian = @"IDocWeiDianCell";
    CLDocWeiDianCell *cell = (CLDocWeiDianCell *)[tableView dequeueReusableCellWithIdentifier:weiDian];
    if (!cell) {
        cell = [[CLDocWeiDianCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:weiDian];        
    }
    cell.weak=self;
    [cell loadData:self.document];

   
    return cell;
}

-(float)caculateRelationCell:(UITableView *)tableView :(int)row{
    if(0==row){
        return 45.f;
    }else{
        //       NSDictionary *dic=[[self.document relations] sgrGetDictionaryForIndex:row-1];
        //        NSString *title=[dic sgrGetStringForKey:@"title"];
        // 最后一个cell并且没有文字链广告，则后空出20像素的位置
        BOOL isLastCell = (row == self.document.entity.relation.count);
        //        CGFloat cellHeihgt = [IfengDocRelationCell caculate:title];
        CGFloat cellHeihgt = 82;
        cellHeihgt = isLastCell?(cellHeihgt+20):cellHeihgt;
        return cellHeihgt;
    }
}

- (UITableViewCell *)createTimeCell:(UITableView *)tableView{
    static NSString *timeCellId=@"doctimeCellId";
    _cell=[tableView dequeueReusableCellWithIdentifier:timeCellId];
    if(!_cell){
        _cell=[[TimeCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:timeCellId];
     
    }
       [_cell setTime:[self.document sourceAndTime]];
    _cell.commentDelegate=self;
    return _cell;
    
}

- (UITableViewCell *)createHTMLElementCell:(UITableView *)tableView
                                   element:(INHtmlElement *)element
                           isLastParagraph:(BOOL)isLastParagraph{
    
  
    if(element.type==HtmlElementTypeText){
        return [self _createIDocRichTextCellWithTableView:tableView
                                               andElement:element
                                          isLastParagraph:isLastParagraph];
      
        
    }else if(HtmlElementTypeImage==element.type){
        return [self createImageCell:tableView :element];
    }else if(HtmlElementTypeGallery==element.type){
        //return [self createImageCell2:tableView :element];
        return  [self createHeadImageCell2:tableView :element];
    }else if(HtmlElementTypeAudio==element.type){
        return [self createAudioCell:tableView :element];
    }
    return nil;
}

- (UITableViewCell *)createImageCell:(UITableView *)tableView :(INHtmlElement *)element{
    static NSString *identifier = @"CLDocImageCell";
    
    CLDocImageCell *cell=[tableView   dequeueReusableCellWithIdentifier:identifier];
    if(!cell){
        cell = [[CLDocImageCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier ];
    }
    [cell loadElement:element];
    
    return cell;

}

- (UITableViewCell *)createImageCell2:(UITableView *)tableView :(INHtmlElement *)element{
    static NSString *identifier = @"CLDocImageCell2";
    
    CLDocImageCell *cell=[tableView   dequeueReusableCellWithIdentifier:identifier];
    if(!cell){
        cell = [[CLDocImageCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier ];
    }
    [cell loadElement:element];
    //self.document.entity.surl=@"http://ips.ifeng.com/video19.ifeng.com/video09/2014/12/13/2800596-102-008-1231.mp4";
    [cell setIsVideo:_isStrNotNull(self.document.entity.surl) url:self.document.entity.surl];
    [cell setIsSlider:_isStrNotNull(self.document.entity.tjid) itemId:self.document.entity.tjid];
    //[cell setHtmlElement:element isShowImg:self.document.isLoadImage];
    
    return cell;
    
}

- (UITableViewCell *)_createIDocRichTextCellWithTableView:(UITableView *)tableView andElement:(INHtmlElement *)element isLastParagraph:(BOOL)isLastParagraph{
//    static NSString *iDocTextCellId=@"CLTextCell";
//    CLTextCell *cell=[tableView dequeueReusableCellWithIdentifier:iDocTextCellId];
//    if(!cell){
//        cell=[[CLTextCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:iDocTextCellId];
//      
//    }
//    [cell loadElement:element];
//    return cell;
    static NSString *iDocTextCellId=@"iDocTextCellId";
    IDocTextCell *cell=[tableView dequeueReusableCellWithIdentifier:iDocTextCellId];
    if(!cell){
        cell=[[IDocTextCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:iDocTextCellId];
        cell.backgroundColor=tableView.backgroundColor;
    }
    cell.isLastParagraph = isLastParagraph;
    
    [cell fillDataWithTextArr:self.document andElement:element];
    return cell;
}

-(UITableViewCell *)createCommentCell:(UITableView *)tableView :(int)row{
    int bottomRowIndex = 0;
    if([self.document.commentsArray count] >=2)
        bottomRowIndex = 3;
    else
        bottomRowIndex = [self.document.commentsArray count]+1;
    
    if(0==row){
        
        return [self createCommentTopCell:tableView];
    }else if(bottomRowIndex==row){
        return [self createCommentBottomCell:tableView];
    }else{
        return [self createCommentCell:tableView
                                   dic:[self.document.commentsArray sgrGetDictionaryForIndex:row-1]
                                   row:row];
    }
}

- (UITableViewCell *)createCommentTopCell:(UITableView *)tableView{
    static NSString *identifier = @"commentTop";
    IfSectionCell *cell = (IfSectionCell *)[tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[IfSectionCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        
        UIImageView *verticalLine = [UIImageView new];
        verticalLine.frame = CGRectMake(15, 20.0f, 2, 14);
        verticalLine.image = [UIImage imageNamed:@"doc_relation_vertical_redline.png"];
        
        
       
        [cell addSubview:verticalLine];
        
        UILabel *label=[[UILabel alloc] init];
        label.font=[UIFont boldSystemFontOfSize:14];
        label.frame=CGRectMake(verticalLine.origin.x+verticalLine.width+8, verticalLine.origin.y-2, 250.0f, label.font.lineHeight);
        label.textAlignment = NSTextAlignmentLeft;
        //label.textColor=ICurrentTheme.docStyle.releativeTitleColor;
        label.textColor=RGB(0xff, 0x30, 0x3b);
       
        label.backgroundColor=[UIColor clearColor];
        label.text=@"热门评论";
        [cell addSubview:label];
        
        UIView *sepertorLine = [UIView new];
        sepertorLine.frame = CGRectMake(53, 49.5, 254, 0.5);
        sepertorLine.backgroundColor=RGB(0xd7, 0xd7, 0xd7);
        
        //sepertorLine.backgroundColor = ICurrentTheme.commentStyle.sectionSepertorLineColor;
        [cell addSubview:sepertorLine];
        [cell bringSubviewToFront:sepertorLine];
    }
    return cell;
}

- (UITableViewCell *)createCommentBottomCell:(UITableView *)tableView{
    static NSString *identifier = @"commentBottom";
    IfSectionCell *cell = (IfSectionCell *)[tableView dequeueReusableCellWithIdentifier:identifier];
    if(!cell){
        cell = [[IfSectionCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        
       
        //cell.backgroundColor=ICurrentTheme.globleStyle.indexTableColor;
        // cell.contentView.backgroundColor=ICurrentTheme.globleStyle.indexTableColor;
        UILabel *label=[[UILabel alloc] init];
        label.font=[UIFont systemFontOfSize:12.0];
        label.frame=CGRectMake((GlobleWidth-82)/2, 12.0f, 82.0f, 12.0f);
        label.textAlignment = NSTextAlignmentCenter;
        //label.textColor=ICurrentTheme.docStyle.commentTitleMoreColor;
        label.textColor=RGB(0xff, 0x30, 0x3b);
      
        label.backgroundColor=[UIColor clearColor];
        label.text=@"查看更多";
        [cell addSubview:label];
    }
    return cell;
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    [cell setSelected:NO animated:YES];
    switch (indexPath.section) {
   
            
        case sec_doc_doc:
            if(self.document.entity.elements){
                [self didselectINHtmlCell:tableView :[self.document.entity.elements  sgrGetType:[INHtmlElement class]
                                                                           forIndex:indexPath.row] :indexPath];

            }
            
            break;
     
        case sec_doc_relation:{
            if (indexPath.row==0) {
                return;
            }
            NSDictionary *dic=[self.document.entity.relation sgrGetDictionaryForIndex:indexPath.row-1];
            [self clickOnList:dic];
            UITableViewCell *cell=[self.tableView cellForRowAtIndexPath:indexPath];
            if([cell isKindOfClass:[IfengDocRelationCell class]]){
                [(IfengDocRelationCell *)cell setIsRead:YES];
            }
            break;
        }
            
        case sec_doc_beFrom:
            [self goToSub];
            break;
            
        case sec_doc_comment:
            [self.panpushAnimation pushDirectly];
            break;
            
            
            break;
            
        default:
            break;
    }
}

- (void)goToComment{
    [self.panpushAnimation pushDirectly];
}

- (void)goToSub{
    CLSubViewController *sub=[CLSubViewController new];
    sub.dic=self.document.entity.dic;
    sub.itemId=[self.document.entity.dic sgrGetStringForKey:@"id"];
    sub.channel=@{@"tpl":@"-1"};
//    sub.itemId=list.classId;
//    sub.objectiveId=list.objectID;
//    sub.channel=[self.categroyDic sgrGetStringForKey:@"channelId"];
    //[sub loadData:list];
    [[CLPushAnimatedRight sharedInstance] pushController:sub];
}

- (void)clickOnList:(NSDictionary *)list{
    int linkType=[[list sgrFGetStringForKey:@"type"] intValue];
    NSString *itemId=[list sgrGetStringForKey:@"id"];
    if(linkType==CLList_sliders){
        CLSlidersViewController *slider=[CLSlidersViewController new];
        slider.itemId=itemId;
        [[CLPushAnimatedRight sharedInstance] pushController:slider];
        
    }else if(linkType==CLList_doc){
        CLDocViewController *doc=[CLDocViewController new];
        doc.itemId=itemId;
        [[CLPushAnimatedRight sharedInstance] pushController:doc];
    }else if(linkType==CLList_topic){
        CLTopicViewController *topic=[CLTopicViewController new];
        topic.itemId=itemId;
        [[CLPushAnimatedRight sharedInstance] pushController:topic];
    }else if(linkType==CLList_video){
        CLVideoViewController *video=[CLVideoViewController new];
        video.itemId=itemId;
        [[CLPushAnimatedRight sharedInstance] pushController:video];
    }else if(linkType==CLList_audio){
        CLDocViewController *doc=[CLDocViewController new];
        doc.itemId=itemId;
        [[CLPushAnimatedRight sharedInstance] pushController:doc];
    }else if(linkType==CLList_live){
        CLLiveViewController *live=[CLLiveViewController new];
        
        live.itemId=itemId;
        [[CLPushAnimatedRight sharedInstance] pushController:live];
        return;
        
        
    }else if(linkType==CLList_web){
        CLWebVeiwController *web = [CLWebVeiwController new];
        
        web.itemId=[list sgrGetStringForKey:@"url"];
        [[CLPushAnimatedRight sharedInstance] pushController:web];
        return;
        
    }
    
}


- (void)didselectINHtmlCell:(CLDocWeiDianCell *)cell{
    CGPoint point=CGPointZero;
    CGRect aframe;
   // if([cell isKindOfClass:[CLDocImageCell class]]){
        aframe=cell.introImage.frame;
        point=cell.introImage.frame.origin;
        point=[cell convertPoint:point toView:self.view];
   // }
    
    self.bigImgView=[[UIView alloc] initWithFrame:self.view.bounds];
    self.bigImgView.backgroundColor=[UIColor blackColor];
    AQRImageZoomView *zoom=[[AQRImageZoomView alloc] initWithFrame:self.bigImgView.bounds];
    zoom.fromRect=CGRectMake(point.x, point.y, aframe.size.width, aframe.size.height);
    [self.bigImgView  addSubview:zoom];
    [self.view addSubview:self.bigImgView];
    [zoom setImageUrl:cell.imgUrl];
    [zoom tapSelect:@selector(cancleImg) target:self];
    UIButton *download=[UIButton buttonWithType:UIButtonTypeCustom];
    download.frame=CGRectMake(GlobleWidth-50.f, GlobleHeight-50.f, 50.f, 50.f);
    [download setImage:[UIImage imageNamed:@"slider_font.png"] forState:UIControlStateNormal];
    download.contentEdgeInsets=UIEdgeInsetsMake(26, 26, 0, 0);
    [self.bigImgView addSubview:download];
    __weak AQRImageZoomView *wz=zoom;
    __weak typeof(self) me=self;
    [download handleControlEvent:UIControlEventTouchUpInside withBlock:^(id sender) {
        UIImage *img=[wz image];
        if(img)
            UIImageWriteToSavedPhotosAlbum(img, me,@selector(image:didFinishSavingWithError:contextInfo:), nil);
        
    }];


}

- (void)gotoSlides{
    if(_isStrNotNull(self.document.entity.tjid)){
        CLSlidersViewController *slider=[CLSlidersViewController new];
        slider.itemId=self.document.entity.tjid;
        [[CLPushAnimatedRight sharedInstance] pushController:slider];
        
    }

}

- (void)didselectINHtmlCell:(UITableView *)tableview :(INHtmlElement *)element :(NSIndexPath *)indexPath{
    if(HtmlElementTypeGallery==element.type){
        if(_isStrNotNull(self.document.entity.tjid)){
            CLSlidersViewController *slider=[CLSlidersViewController new];
            slider.itemId=self.document.entity.tjid;
            [[CLPushAnimatedRight sharedInstance] pushController:slider];

        }
    }else if(HtmlElementTypeImage==element.type){
        UITableViewCell *cell=[self.tableView cellForRowAtIndexPath:indexPath];
        CGPoint point=CGPointZero;
        CGRect aframe;
        if([cell isKindOfClass:[CLDocImageCell class]]){
            aframe=((CLDocImageCell *)cell).docImageView.frame;
            point=((CLDocImageCell *)cell).docImageView.frame.origin;
            point=[cell convertPoint:point toView:self.view];
        }
        
        self.bigImgView=[[UIView alloc] initWithFrame:self.view.bounds];
        self.bigImgView.backgroundColor=[UIColor blackColor];
        AQRImageZoomView *zoom=[[AQRImageZoomView alloc] initWithFrame:self.bigImgView.bounds];
        zoom.fromRect=CGRectMake(point.x, point.y, aframe.size.width, aframe.size.height);
        [self.bigImgView  addSubview:zoom];
        [self.view addSubview:self.bigImgView];
        [zoom setImageUrl:element.strValue];
        [zoom tapSelect:@selector(cancleImg) target:self];
        UIButton *download=[UIButton buttonWithType:UIButtonTypeCustom];
        download.frame=CGRectMake(GlobleWidth-50.f, GlobleHeight-50.f, 50.f, 50.f);
        [download setImage:[UIImage imageNamed:@"slider_load_icon.png"] forState:UIControlStateNormal];
        download.contentEdgeInsets=UIEdgeInsetsMake(26, 26, 0, 0);
        [self.bigImgView addSubview:download];
        __weak AQRImageZoomView *wz=zoom;
        __weak typeof(self) me=self;
        [download handleControlEvent:UIControlEventTouchUpInside withBlock:^(id sender) {
            UIImage *img=[wz image];
            if(img)
                UIImageWriteToSavedPhotosAlbum(img, me,@selector(image:didFinishSavingWithError:contextInfo:), nil);

        }];
    }
}

#pragma mark - download delegate
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
    NSString * message = [error description];
    if ([message length]==0) {
        [[CLGloble sharedInstance] showTieSuccessMessage:@"提示" subMessage:@"保存成功"];
    }
    else
    {
        message = @"请开启相册访问权限";
        [[CLGloble sharedInstance] showTieAlertMessage:@"提示" subMessage:message];
    }
}

- (void)cancleImg{
    [UIView animateWithDuration:0.2 animations:^{
        self.bigImgView.alpha=0;
    } completion:^(BOOL finished) {
        [self.bigImgView removeFromSuperview];
        self.bigImgView=nil;
        [self picShowComplete];
    }];
}

- (UITableViewCell *)createCommentCell:(UITableView *)tableView dic:(NSDictionary *)dic row:(int)row{
    static NSString *identifier = @"commentCellId";
    /*
     HotCommentCell *cell=(HotCommentCell *)[tableView dequeueReusableCellWithIdentifier:identifier];
     if(!cell){
     cell=[[HotCommentCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
     }
     if(dic && [dic isKindOfClass:[NSDictionary class]])
     [cell setComment:dic];
     */
    CommentCommonCell *cell = (CommentCommonCell *)[tableView dequeueReusableCellWithIdentifier:identifier];
    if(cell == nil){
        cell = [[CommentCommonCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    cell.delegate=self;
    cell.comeFrom = @"doc";
    cell.indexPath = [NSIndexPath indexPathForRow:row inSection:sec_doc_comment];
    cell.dataDic = dic;
    [cell setUpSubViews];
   
    return cell;
}

-(BOOL)automaticallyAdjustsScrollViewInsets{
    return NO;
}

- (UITableViewCell *)createHeadImageCell:(UITableView *)tableView
{
    static NSString *headImageId = @"CLDocHeadImgCell";
    CLDocHeadImgCell *cell = [tableView dequeueReusableCellWithIdentifier:headImageId];
    if(cell == nil)
    {
        cell = [[CLDocHeadImgCell alloc] initWithStyle:UITableViewCellStyleDefault
                                       reuseIdentifier:headImageId];
     
    }
    [cell loadImgUrl:self.document.entity.bigpic];
    //self.document.entity.vurl=@"http://ips.ifeng.com/video19.ifeng.com/video09/2014/12/13/2800596-102-008-1231.mp4";
    [cell setIsVideo:_isStrNotNull(self.document.entity.vurl) url:self.document.entity.vurl];
    return cell;
}

- (UITableViewCell *)createHeadImageCell2:(UITableView *)tableView :(INHtmlElement *)element
{
    static NSString *headImageId = @"CLDocHeadImgCell2";
    CLDocHeadImgCell *cell = [tableView dequeueReusableCellWithIdentifier:headImageId];
    if(cell == nil)
    {
        cell = [[CLDocHeadImgCell alloc] initWithStyle:UITableViewCellStyleDefault
                                       reuseIdentifier:headImageId];
        
    }
    [cell loadImgUrl:element.strValue];
    //self.document.entity.vurl=@"http://ips.ifeng.com/video19.ifeng.com/video09/2014/12/13/2800596-102-008-1231.mp4";
    [cell setIsVideo:_isStrNotNull(self.document.entity.surl) url:self.document.entity.surl];
    [cell setIsSlider:_isStrNotNull(self.document.entity.tjid) itemId:self.document.entity.tjid];
    return cell;
}

- (UITableViewCell *)createTitleCell:(UITableView *)tableView{
    static NSString *titleCellId=@"docTitleCellId";
    TitleCell *cell=[tableView dequeueReusableCellWithIdentifier:titleCellId];
    if(!cell){
        cell = [[TitleCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:titleCellId];
      
    }
    [cell setTitle:self.document.entity.title];
    return cell;

}

- (UITableViewCell *)createFocusCell:(UITableView *)tableView{
    static NSString *titleCellId=@"docTitleCellId";
    CLDocFocusCell *cell=[tableView dequeueReusableCellWithIdentifier:titleCellId];
    if(!cell){
        cell = [[CLDocFocusCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:titleCellId];
    }
    [cell setText:self.document.entity.smallText withTitle:self.document.entity.smallTextTitle];
    return cell;
    
}

- (void)createAudioView{
    self.tool.view.hidden = YES;
    self.audioView=[[UIView alloc] init];
    self.audioView.frame=CGRectMake(0, GlobleHeight-80.f, GlobleWidth, 80);
    self.audioView.backgroundColor=RGB(240, 240, 240);
    [self.view addSubview:self.audioView];
    
    CALayer *line=[CALayer layer];
    line.frame=CGRectMake(0, 0, GlobleWidth, 0.5);
    [self.audioView.layer addSublayer:line];
    
    self.slider=[[UISlider alloc] init];
    self.slider.frame=CGRectMake(12.f, 2.f, GlobleWidth-24.f, 20.f);
    [self.audioView addSubview:self.slider];
    
    [self.slider setThumbImage:[UIImage imageNamed:@"doc_audio_point.png"] forState:UIControlStateNormal];
    [self.slider setMinimumTrackTintColor:[UIColor redColor]];
   // [self.slider s];
    __weak typeof(self) me=self;
    
    [self.slider handleControlEvent:UIControlEventTouchDragInside withBlock:^(id sender){
        
        me.isSlider=YES;
        
    }];
    
    [self.slider handleControlEvent:UIControlEventTouchUpInside withBlock:^(id sender){
        
        me.isSlider=NO;
        if([IFAudioPlayerManager shareInstance].isPlaying){
            [[IFAudioPlayerManager shareInstance] seekToTime:me.slider.value];
            double total=[IFAudioPlayerManager shareInstance].player.duration;
            me.sliderLabel.text=[NSString stringWithFormat:@"%@/%@",
                                   [[IFAudioPlayerManager shareInstance] formatSecond:me.slider.value],
                                   [[IFAudioPlayerManager shareInstance] formatSecond:total]];

        }
        ;
        
    }];


    UIButton *back=[UIButton buttonWithType:UIButtonTypeCustom];
    [back setImage:[UIImage imageNamed:@"tb_back.png"] forState:UIControlStateNormal];
    [back setContentEdgeInsets:UIEdgeInsetsMake(5, 5, 5, 5)];
    back.frame=CGRectMake(13, self.slider.bottom+7.f+8, 34.f, 34.f);
    
    [back handleControlEvent:UIControlEventTouchUpInside withBlock:^(id sender) {
        [[me k_currentController].dispatchObj pop];
    }];
    [self.audioView addSubview:back];
    
    self.sliderLabel=[UILabel new];
    self.sliderLabel.font=[UIFont systemFontOfSize:12.f];
    self.sliderLabel.textColor=RGB(0x56, 0x56, 0x5e);
    self.sliderLabel.frame=CGRectMake(back.right+8, back.top+3, 85.f, self.sliderLabel.font.lineHeight);
    [self.audioView addSubview:self.sliderLabel];
    
    
    self.play=[UIButton buttonWithType:UIButtonTypeCustom];
    self.play.frame=CGRectMake(139, self.slider.bottom+12.f, 40.f, 40.f);
    [self.play setImage:[UIImage imageNamed:@"音频内文_播放.png"] forState:UIControlStateNormal];
    [self.audioView addSubview:self.play];
    
    self.more=[UIButton buttonWithType:UIButtonTypeCustom];
    self.more.frame=CGRectMake(GlobleWidth-16-32, self.slider.bottom+2.f+12.f, 36, 36);
    [self.more setContentEdgeInsets:UIEdgeInsetsMake(10, 10, 10, 10)];
    [self.more setImage:[UIImage imageNamed:@"音频内文_更多.png"] forState:UIControlStateNormal];
    [self.audioView addSubview:self.more];
    
    [self.more handleControlEvent:UIControlEventTouchUpInside withBlock:^(id sender) {
        
        me.audioView.hidden=YES;
        me.tool.view.hidden = NO;
        [me.tool showFontPannel:0 withIsYinpin:YES];
        
    }];
     
    
    //__weak typeof(self) me=self;
    [self.play handleControlEvent:UIControlEventTouchUpInside withBlock:^(id sender) {
        IFAudioPlayerManager *ap=[IFAudioPlayerManager shareInstance];
        
        NSString *tag=me.document.entity.itmeId;
        if(![tag isEqualToString:[IFAudioPlayerManager shareInstance].tag]){
            [[IFAudioPlayerManager shareInstance] stop];
        }
        
        
        if(![ap isPlaying]){
            
            [ap play];
            [IFAudioPlayerManager shareInstance].tag=tag;
            [IFAudioPlayerManager shareInstance].delegate=me;
            
            [[IFAudioPlayerManager shareInstance] playWithURLString:me.document.entity.audio  title:me.document.entity.title];
            [me.play setImage:[UIImage imageNamed:@"音频内文_暂停.png"] forState:UIControlStateNormal];
            [[IFAudioPlayerManager shareInstance] hiddenStateWindow];
            
            
        }else if([ap isPause]){
            [ap resume];
            
            [me.play setImage:[UIImage imageNamed:@"音频内文_暂停.png"] forState:UIControlStateNormal];
            [[IFAudioPlayerManager shareInstance] hiddenStateWindow];
            
        }else if([ap isRunning]) {
            [ap pause];
            [me.play setImage:[UIImage imageNamed:@"音频内文_播放.png"] forState:UIControlStateNormal];
        }else{
            
        }
        
        [[IFCoreDataManager sharedInstance] performBlock:^(NSManagedObjectContext *moc) {
            CLList *list=(CLList *)[CLList fetchWithPredict:[NSPredicate predicateWithFormat:@"itemId=%@",me.document.entity.itmeId]
                                          withMOC:moc];
            list.slider1=[NSString stringWithFormat:@"%ud",arc4random()];
            CLCollect *collect=(CLCollect *)[CLCollect fetchWithPredict:[NSPredicate predicateWithFormat:@"itemId=%@",me.document.entity.itmeId]
                                                                withMOC:moc];
            collect.slider1=[NSString stringWithFormat:@"%ud",arc4random()];
            
            [[IFCoreDataManager sharedInstance] saveContext:moc ToPersistentStore:nil];
        }];
        
        

    }];
    
    
    
}

//- (void)willpause:(NSString *)tag{
//   [self.play setImage:[UIImage imageNamed:@"音频内文_播放.png"] forState:UIControlStateNormal];
//    
//}

- (void)showYinpinTool:(NSNotification *)aNotification {
    self.audioView.hidden=NO;
    self.tool.view.hidden = YES;
}

- (void)checkStatus{
    
    
    if(![self.document.entity.itmeId isEqualToString:[IFAudioPlayerManager shareInstance].tag])return;

    
    
    IFAudioPlayerManager *ap=[IFAudioPlayerManager shareInstance];
    ap.delegate=self;
    
    self.sliderLabel.text=[NSString stringWithFormat:@"%@/%@",[ap formatSecond:ap.player.progress],[ap formatSecond:ap.player.duration]];
    
    self.slider.maximumValue=ap.player.duration;
  
    self.slider.minimumValue=0.f;
    [self.slider setValue:ap.player.progress animated:NO];
  
    
    if(![ap isPause]){
        
        [self.play setImage:[UIImage imageNamed:@"音频内文_暂停.png"] forState:UIControlStateNormal];
        
       
        
    }else{
        
         [self.play setImage:[UIImage imageNamed:@"音频内文_播放.png"] forState:UIControlStateNormal];
    }
    
}

- (void)finishwithReason:(STKAudioPlayerStopReason)stopReason andProgress:(double)progress andDuration:(double)duration{
    [[IFAudioPlayerManager shareInstance] stop];
    [self.play setImage:[UIImage imageNamed:@"音频内文_播放.png"] forState:UIControlStateNormal];
    self.sliderLabel.text=@"";
    self.slider.value=0;
}

- (void)playingStstusTotalTime:(double) total current:(double)current{
    self.sliderLabel.text=[NSString stringWithFormat:@"%@/%@",
                         [[IFAudioPlayerManager shareInstance] formatSecond:current],
                         [[IFAudioPlayerManager shareInstance] formatSecond:total]];
    self.slider.maximumValue=total;
}

- (void)audioProgerss:(float)progerss{
    if(self.isSlider) return;
    double total=[IFAudioPlayerManager shareInstance].player.duration;
    self.sliderLabel.text=[NSString stringWithFormat:@"%@/%@",
                         [[IFAudioPlayerManager shareInstance] formatSecond:progerss],
                         [[IFAudioPlayerManager shareInstance] formatSecond:total]];
    [self.slider setValue:progerss animated:NO];
}



- (void)creatHeadView{

        
        _headerView =[[UIView alloc] init];
        _headerView.frame = CGRectMake(0,0, GlobleWidth,(GlobleWidth*9.f)/16.f);
        self.headframe=_headerView.frame;
        _headImgView.backgroundColor = [UIColor redColor];
        
        
        _headImgView = [[CLDocHeadImgCell alloc] initWithStyle:UITableViewCellStyleDefault
                                               reuseIdentifier:nil];
        
        _headImgView.backgroundColor = [UIColor clearColor];
        [_headImgView loadImgUrl:self.document.entity.bigpic];
        
        [_headImgView setIsVideo:_isStrNotNull(self.document.entity.vurl) url:self.document.entity.vurl];
        
        
        
        [_headerView addSubview:_headImgView];
        
        [self.webView.scrollView addSubview:_headerView];
        
    [_headImgView convertRect:_headImgView.play.frame toView:self.webView.scrollView];
    [self.webView.scrollView addSubview:_headImgView.play];
    

}

- (void)playVideo:(int) index frame:(CGRect )frame{
    if (self.document.entity.surl&& [self.document.entity.surl length] > 4){
        [[CLGloble sharedInstance] clearMovie];
        //CGRect frame=me.headImage.frame;
        IFMoviePlayerController *moviePlayer = [[IFMoviePlayerController alloc] initWithContentURL:nil WithType:IFVideo_Type_Document];
        //self.moviePlayer.delegate = self;
        //self.moviePlayer.repeatMode = MPMovieRepeatModeOne;
        
        [moviePlayer.view setFrame:frame];
        
        //IEmbedMoviePlayer *player=[[IEmbedMoviePlayer alloc] initWithFrame:frame];
        //        IEmbedMoviePlayer *player =[IEmbedMoviePlayer getEmbedMoviePlayer:frame];
        //              [player setframe:frame];
        //        player.playerController.videoIdStr = self.documentId;
        //        self.moviePlayer = player;
        [self.webView.scrollView addSubview:moviePlayer.view];
        
        [moviePlayer setContentURL:[NSURL URLWithString:self.document.entity.surl]];
        [moviePlayer prepareToPlay];
        [moviePlayer play];
       self.pc=moviePlayer;
        [CLGloble sharedInstance].singleMovie=moviePlayer;
        
        
    }

}

- (void)showBigPic:(NSString *)url frame:(CGRect) frame{
    
    if(self.isShowPic) return;
    self.isShowPic=YES;
    
    CGPoint point=CGPointZero;
    CGRect aframe;
  
    aframe=frame;
        point=frame.origin;
        point=[self.webView.scrollView convertPoint:point toView:self.view];
    
    
    self.bigImgView=[[UIView alloc] initWithFrame:self.view.bounds];
    self.bigImgView.backgroundColor=[UIColor blackColor];
    AQRImageZoomView *zoom=[[AQRImageZoomView alloc] initWithFrame:self.bigImgView.bounds];
    zoom.fromRect=CGRectMake(point.x, point.y, aframe.size.width, aframe.size.height);
    [self.bigImgView  addSubview:zoom];
    [self.view addSubview:self.bigImgView];
    [zoom setImageUrl:url];
    [zoom tapSelect:@selector(cancleImg) target:self];
    UIButton *download=[UIButton buttonWithType:UIButtonTypeCustom];
    download.frame=CGRectMake(GlobleWidth-50.f, GlobleHeight-50.f, 50.f, 50.f);
    [download setImage:[UIImage imageNamed:@"slider_load_icon.png"] forState:UIControlStateNormal];
    download.contentEdgeInsets=UIEdgeInsetsMake(26, 26, 0, 0);
    [self.bigImgView addSubview:download];
    __weak AQRImageZoomView *wz=zoom;
    __weak typeof(self) me=self;
    [download handleControlEvent:UIControlEventTouchUpInside withBlock:^(id sender) {
        UIImage *img=[wz image];
        if(img)
            UIImageWriteToSavedPhotosAlbum(img, me,@selector(image:didFinishSavingWithError:contextInfo:), nil);
        
    }];
    
}

- (void)picShowComplete
{
    self.webView.scrollView.scrollEnabled=YES;
    self.tableView.scrollEnabled=YES;
    self.isShowPic=NO;
}

- (void)webViewDidFinishLoad:(UIWebView *)webView{
    CGSize size= [self.webView sizeThatFits:CGSizeZero];
    
    
    self.webView.scrollView.contentSize=CGSizeMake(GlobleWidth, size.height);
    self.fitSizeY=size.height;
    
    NSString *str=[self.webView stringByEvaluatingJavaScriptFromString:@"lastObjFrame();"];
    NSArray *arr=[str componentsSeparatedByString:@","];
    if([arr count]==4){
        
        float y=[arr[1] floatValue];
        if(y>0 && y<self.webView.height){
            self.webView.height=y+5.f;
            // 把contentSize改小会导致下面的tableView上移.
            // 但bindView实现是通过contentSize来做padding的, 实际的contentSize会更大.
            // 所以webView仍然会把期望的高度内容画出来, 导致对移上去的tableView造成覆盖.
            // self.webView.scrollView.contentSize=CGSizeMake(GlobleWidth, self.webView.height);
            self.fitSizeY=y+5.f;
        }
        
    }
    
    self.jsContext=[self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
    self.action=[IFDocAction2 new];
    self.jsContext[@"grounds"]=self.action;
    self.action.doc=self;

    
    if(_isStrNotNull(self.document.entity.bigpic)){
        [self creatHeadView];
    }
    
    if(self.document.entity.weidianTextHeight>0){
        
        str=[self.webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"divFrameByName('%@')",@"top_weidian"]];
        arr=[str componentsSeparatedByString:@","];
        if([arr count]==4){

        
        
        CLDocWeiDianCell *cell = nil;
       
            cell = [[CLDocWeiDianCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
        
        cell.weak=self;
        [cell loadData:self.document];
            
            cell.frame=CGRectMake(0, [arr[1] floatValue], GlobleWidth, self.document.entity.weidianTextHeight);
            [self.webView.scrollView addSubview:cell];
        }

    }
    
    if(_isStrNotNull(self.document.entity.smallText)){
        str=[self.webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"divFrameByName('%@')",@"top_info"]];
        arr=[str componentsSeparatedByString:@","];
        if([arr count]==4){
            CLDocFocusCell *cell=nil;
           
            cell = [[CLDocFocusCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
            
            [cell setText:self.document.entity.smallText withTitle:self.document.entity.smallTextTitle];
            
            cell.frame=CGRectMake(0, [arr[1] floatValue], GlobleWidth, self.document.entity.smallTextHeight-9.f);
            
            [self.webView.scrollView addSubview:cell];
        }
    }
    
    __weak typeof(self) me=self;
    [[SgrGCD sharedInstance] enqueueForeground:^{
        
        float loazSize=3000;
        if([CLDocModel sharedInstance].loadLevel==3){
            loazSize=300;
        }else if([CLDocModel sharedInstance].loadLevel==2){
            loazSize=1000;
        }
        [me.webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"addLoadLazy(%f);",loazSize]];
//        if(me.markView){
//            [UIView animateWithDuration:0.5 animations:^{
//                me.markView.alpha=0;
//            } completion:^(BOOL finished) {
//                [me.markView removeFromSuperview];
//                me.markView=nil;
//            }];
//        }
    }];
    
    [[SgrGCD sharedInstance] enqueueForeground:^{
        [me.tableView reloadData];
        [me requestComment];
    }];

    

}



@end
